<template>
	<view>
		<view class="one">
			<view class=" u-flex u-row-between" style="padding: 10rpx 30rpx;">
				<view class="">消息</view>
				<u-image @click="clearMes" src="https://www.sqkjkj.vip/wxImg/mymassage/img1.png" mode="aspectFill"
					width="34rpx" height='34rpx'></u-image>
			</view>
			<view class="" style="padding: 10rpx 20rpx;">
				<u-row>
					<u-col span="4" v-for="(item,index) in list" :key="index">
						<view class="u-m-t-40 u-flex-col u-col-center u-relative"
							@click="$u.route(`/subcontract/mymassage/systemMessages/systemMessages?type=${item.type}`)">

							<view v-if="item.un_read_count!==0"
								class="u-absolute u-z-300 u-r-40 u-t-0 u-w-40 u-h-40 u-l-h-40 u-b-r-40 u-text-center u-font-26 cl_FFF bg_FC3533FF">
								{{item.un_read_count}}
							</view>
							<u-image v-if="item.type==0" src="https://www.sqkjkj.vip/wxImg/mymassage/img2.png"
								mode="aspectFill" width="107rpx" height='107rpx'></u-image>
							<u-image v-else-if="item.type==1" src="https://www.sqkjkj.vip/wxImg/mymassage/img3.png"
								mode="aspectFill" width="107rpx" height='107rpx'></u-image>
							<u-image v-else="item.type==2" src="https://www.sqkjkj.vip/wxImg/mymassage/img4.png"
								mode="aspectFill" width="107rpx" height='107rpx'></u-image>
							<view class="cl_333333FF u-font-28">{{item.name}}</view>
						</view>
					</u-col>
				</u-row>
			</view>
		</view>
		<view v-for="(m,mi) in mess" :key="mi" class="u-p-l-30 u-p-r-30 u-p-b-30 u-p-t-20" style="border-bottom: 1rpx solid #E2EBF4FF;">
			<view v-if="m.is_read==0"  class="u-flex u-row-right">
				<view class="u-w-15 u-h-15 u-m-b-20 u-b-r-10 bg_FC3533FF">
					
				</view>
			</view>
			<view class=" u-flex u-row-between">
				<view class="u-flex">
					<u-image v-if="m.type==0" src="https://www.sqkjkj.vip/wxImg/mymassage/img2.png" mode="aspectFill"
						width="107rpx" height='107rpx'></u-image>
					<u-image v-else-if="m.type==1" src="https://www.sqkjkj.vip/wxImg/mymassage/img3.png"
						mode="aspectFill" width="107rpx" height='107rpx'></u-image>
					<u-image v-else="m.type==2" src="https://www.sqkjkj.vip/wxImg/mymassage/img4.png" mode="aspectFill"
						width="107rpx" height='107rpx'></u-image>
					<view @click="$u.route(`/subcontract/mymassage/systemMessages/detail?announce_id=${m.id}`)"
						class="u-m-l-20">
						<view class="u-font-30 u-w-600 u-flex u-row-between">
							<view class="">{{m.type==0?'系统消息':m.type==1?'订单消息':'通知消息'}}</view>
							<view class="u-p-r-20">{{m.create_time}}</view>
						</view>
						<!-- #ifdef MP-WEIXIN-->
						<view class="u-font-20 u-m-t-10 u-w-450 text-cut-2" style="max-height: 400rpx;">
							<u-parse :html="m.detail"></u-parse>
						</view>
						<!-- #endif -->
						<!-- #ifndef MP-WEIXIN-->
						<view class="u-font-20 u-m-t-10 u-w-450 text-cut-2" style="max-height: 400rpx;">
							<u-parse :html="m.detail"></u-parse>
						</view>
						<!-- #endif -->
					</view>
				</view>
			</view>
		</view>
		<!-- 加载更多 -->
		<u-loadmore :status="status" icon-type="circle" margin-top="20" margin-bottom="20" />
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				messParams: {
					type: -1,
					page: 1,
					page_size: 20
				},
				mess: [],
				status: 'loadmore',
			}
		},
		onShow() {
			this.announce_type_list()
			this.clear()
			this.announce_list()
		},
		// 下拉到底事件
		onReachBottom() {
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.announce_list();
		},
		methods: {
			backs() {
				uni.navigateBack()
			},
			clearMes() {
				this.$api.announce_clear({}, res => {
					if (res.data.code == 1) {
						this.$refs.uToast.show({
							title: res.data.msg,
							callback: res => {
								this.announce_type_list()
							}
						})
					}
				})
			},
			async announce_type_list() {
				await this.$api.announce_type_list({}, res => {
					if (res.data.code == 1) {
						this.list = res.data.data
					}
				})
			},
			clear() {
				this.mess = [];
				this.messParams.page = 1;
			},
			async announce_list() {
				await this.$api.announce_list(this.messParams, res => {
					if (res.data.code == 1) {
						if (res.data.data.data.length < 20) {
							this.status = 'nomore';
						} else {
							this.messParams.page = this.messParams.page + 1;
							this.status = 'loadmore';
						}
						this.mess = this.mess.concat(res.data.data.data);
						uni.stopPullDownRefresh();
					}
				})
			},

		}
	}
</script>

<style scoped>
	.one {
		width: 750rpx;
		height: 350rpx;
		background: url('https://www.sqkjkj.vip/wxImg/mymassage/img.png') no-repeat;
		background-size: 100% 100%;
	}
</style>
